package cz.proks.schoolpupilbook.gwt.core;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;

import cz.proks.schoolpupilbook.gwt.core.handler.CommentSubmitHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.CourseFormHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.HistoryChangeHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.LoginHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.MarkFormHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.UserCourseRelationFormHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.UserFormHandler;
import cz.proks.schoolpupilbook.gwt.core.handler.UserRelationFormHandler;
import cz.proks.schoolpupilbook.gwt.widget.common.CourseForm;
import cz.proks.schoolpupilbook.gwt.widget.common.LectorView;
import cz.proks.schoolpupilbook.gwt.widget.common.LoginForm;
import cz.proks.schoolpupilbook.gwt.widget.common.MarkForm;
import cz.proks.schoolpupilbook.gwt.widget.common.ParentView;
import cz.proks.schoolpupilbook.gwt.widget.common.UserCourseRelationForm;
import cz.proks.schoolpupilbook.gwt.widget.common.UserForm;
import cz.proks.schoolpupilbook.gwt.widget.common.UserRelationForm;
import cz.proks.schoolpupilbook.shared.Constants;

public class CoreEntryPoint implements EntryPoint {

	@Override
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get(Constants.SCHOOL_PUPIL_BOOK_DIV);
		EventBus eventBus = SchoolPupilBookFactory.getEventBus();
		
		LoginHandler loginHandler = new LoginHandler();
		UserFormHandler userFormHandler = new UserFormHandler();
		CourseFormHandler courseFormHandler = new CourseFormHandler();
		MarkFormHandler markFormHandler = new MarkFormHandler();
		UserRelationFormHandler userRelationFormHandler = new UserRelationFormHandler();
		UserCourseRelationFormHandler userCourseRelationFormHandler = new UserCourseRelationFormHandler();
		CommentSubmitHandler commentSubmitHandler = new CommentSubmitHandler();
		
		eventBus.addHandler(LoginForm.SubmitEvent.TYPE, loginHandler);
		eventBus.addHandler(UserForm.SubmitEvent.TYPE, userFormHandler);
		eventBus.addHandler(CourseForm.SubmitEvent.TYPE, courseFormHandler);
		eventBus.addHandler(MarkForm.SubmitEvent.TYPE, markFormHandler);
		eventBus.addHandler(UserRelationForm.SubmitEvent.TYPE, userRelationFormHandler);
		eventBus.addHandler(UserCourseRelationForm.SubmitEvent.TYPE, userCourseRelationFormHandler);
		eventBus.addHandler(ParentView.CommentSubmitEvent.TYPE, commentSubmitHandler);
		eventBus.addHandler(LectorView.CommentSubmitEvent.TYPE, commentSubmitHandler);
		
		History.addValueChangeHandler(new HistoryChangeHandler(rootPanel));
				
		History.fireCurrentHistoryState();
	}
}
